package com.design.pattern.observer.simple;

import java.util.ArrayList;
import java.util.List;

public class ConcerteOauth implements Oauth {
    private String name;

    public ConcerteOauth(String name) {
        this.name = name;
    }

    private List<User> users=new ArrayList<>();
    @Override
    public void addObserver(User u) {
        users.add(u);
    }

    @Override
    public void delObserver(User u) {
        users.remove(u);
    }

    @Override
    public void notifyAllObserver(String message) {
        for (User user:users){
            user.update(message);
        }
    }

    @Override
    public void publishNew(String message) {
        System.out.println(name+"发布了新文章："+message);
        notifyAllObserver(message);
    }
}
